from app.core.send_method import SendMethod
from app.core.read_excel import ExcelData
from app.core.login_token import login
from app.core.log import Log
import unittest, sys
from ddt import ddt, data
import jsonpath, json

method = SendMethod()
test_data = ExcelData("testcase.xlsx", "Sheet1").read_excel()


@ddt
class TestAddTopic(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        header = {'Authorization': login(), "Content-Type": "application/json"}
        method.get_header(header)

    def setUp(self) -> None:
        pass

    @data(*test_data)
    def test_add_topic(self, data):
        Log().log("-" * 60 + sys._getframe().f_code.co_name + "-" * 60, "info")
        method.get_url("/api/topicWarehouse/personalManage/add")
        value = json.loads(data["param"])
        method.get_data(value)
        response = method.post_with_json()
        status_code = jsonpath.jsonpath(response, "$..status_code")[0]
        if status_code != 200:
            Log().log(jsonpath.jsonpath(response, "$..message")[0], "info")
        else:
            pass
        self.assertEqual(status_code, int(data["stauts_code"]))

    def tearDown(self) -> None:
        pass

    @classmethod
    def tearDownClass(cls) -> None:
        pass


if __name__ == '__main__':
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestAddTopic))
    unittest.TextTestRunner(verbosity=2).run(suite)
